package com.cmpe.av.androidservice;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cmpe.av.logic.ReportLogic;
import com.cmpe.av.logic.UserLogic;
import com.cmpe.av.model.Tag;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Servlet implementation class GetTags
 */
@WebServlet("/GetTags")
public class GetTags extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private List<Tag> tags;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetTags() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.reset();
		
		try {
			tags = new ReportLogic().getTags();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		ObjectMapper mapper = new ObjectMapper();
		PrintWriter out = response.getWriter();
		out.write(mapper.writeValueAsString(tags));
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	public List<Tag> getTags(){
		ReportLogic msAccess;
		tags= new ArrayList<Tag>();
		try{
			msAccess = new ReportLogic();
			tags=msAccess.getTags();
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return tags;
	}

}
